home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-04 / netprog.zip / NETPROG.TAR / lib / ttyraw.c < prev    next >
C/C++ Source or Header  |  1989-12-17  |  970b  |  45 lines

  1. /*
  2.  * Put a terminal device into RAW mode with ECHO off.
  3.  * Before doing so we first save the terminal's current mode,
  4.  * assuming the caller will call the tty_reset() function
  5.  * (also in this file) when it's done with raw mode.
  6.  */
  7.  
  8. #include    <sys/types.h>
  9. #include    <sys/ioctl.h>
  10.  
  11. static struct sgttyb    tty_mode;    /* save tty mode here */
  12.  
  13. int
  14. tty_raw(fd)
  15. int    fd;        /* of terminal device */
  16. {
  17.     struct sgttyb    temp_mode;
  18.  
  19.     if (ioctl(fd, TIOCGETP, (char *) &temp_mode) < 0)
  20.         return(-1);
  21.     tty_mode = temp_mode;        /* save for restoring later */
  22.  
  23.     temp_mode.sg_flags |= RAW;    /* turn RAW mode on */
  24.     temp_mode.sg_flags &= ~ECHO;    /* turn ECHO off */
  25.     if (ioctl(fd, TIOCSETP, (char *) &temp_mode) < 0)
  26.         return(-1);
  27.  
  28.     return(0);
  29. }
  30.  
  31. /*
  32.  * Restore a terminal's mode to whatever it was on the most
  33.  * recent call to the tty_raw() function above.
  34.  */
  35.  
  36. int
  37. tty_reset(fd)
  38. int    fd;        /* of terminal device */
  39. {
  40.     if (ioctl(fd, TIOCSETP, (char *) &tty_mode) < 0)
  41.         return(-1);
  42.  
  43.     return(0);
  44. }
  45.